<?php
/**
 * Created by PhpStorm.
 * User: weijer
 * Date: 2018/10/26
 * Time: 21:17
 */

namespace common\validate;

use think\Validate;

class Chat extends BaseValidate
{
    //验证规则
    protected $rule = [];

    // Fields 验证场景定义
    public function sceneFields()
    {
        return $this;
    }

    // Find 验证场景定义
    public function sceneFind()
    {
        return $this->append('param', 'require')
            ->append('param.filter', 'array');
    }

    // Select 验证场景定义
    public function sceneSelect()
    {
        return $this->append('param', 'require')
            ->append('param.filter', 'array')
            ->append('param.page', 'array');
    }

    // Create 验证场景定义
    public function sceneCreate()
    {
        return $this->append('data.name', 'require|max:128')
            ->append('data.code', 'max:128');
    }

    // Update 验证场景定义
    public function sceneUpdate()
    {
        return $this->append('data.id', 'require')
            ->append('data.name', 'max:128')
            ->append('data.code', 'max:128');
    }

    // Delete 验证场景定义
    public function sceneDelete()
    {
        return $this->append('param.filter', 'require|array');
    }

    // CreateChat 验证场景定义
    public function sceneCreateChat()
    {
        return $this->append('data.receiver', 'require');
    }

    // GetUserUnreadChatMessage 验证场景定义
    public function sceneGetUserUnreadChatMessage()
    {
        return $this->append('param.filter.chat_global_id', 'require');
    }

    // GetBaseInfo 验证场景定义
    public function sceneGetBaseInfo()
    {
        return $this->append('param.filter.global_id', 'require');
    }

    // GetUserList 验证场景定义
    public function sceneGetUserList()
    {
        return $this->append("param.filter", "require|array")
            ->append("param.fields", "require");
    }

    // CreateTenantChat 验证场景定义
    public function sceneCreateTenantChat()
    {
        return $this->append("param", "array")
            ->append("param.filter", "array");
    }

    // ProjectChatList 验证场景定义
    public function sceneProjectChatList()
    {
        return $this->append("param", "array")
            ->append("param.filter", "array")
            ->append("param.page", "array");
    }

    // OutSideChatList 验证场景定义
    public function sceneOutSideChatList()
    {
        return $this->append("param", "array")
            ->append("param.filter", "array")
            ->append("param.page", "array");
    }

    public function sceneCreateGroupChats()
    {
        return $this->append("id", "require")
            ->append("type", "require");
    }

    public function sceneCreateGroupChat()
    {
        return $this->append("data", "require")
            ->append("data.receiver", "require");
    }

    //获取会话列表
    public function sceneGetUserChatList()
    {
        return $this->append("param", "array")
            ->append("param.filter", "array")
            ->append("param.filter.type", "in:system,one2one,group,project")
            ->append("param.page", "array");
    }

    // WriteChatEditedAt 验证场景定义
    public function sceneWriteChatEditedAt()
    {
        return $this->append('param.filter', 'array');
    }

    public function sceneFindUserChat()
    {
        return $this->append('param', 'require')
            ->append('param.find_method', 'in:base_filter,notify_user_mark')
            ->append('param.filter', 'array')
            ->append('param.filter.notify_user_mark', 'requireIf:param.find_method,notify_user_mark');
    }

    public function sceneGetChatIsUnread()
    {
        $this->append('param.filter', 'require');
    }

    public function sceneUpdateAvatar()
    {
        $this->append('data.chat_global_id', 'require')
            ->append('data.extra_file_media', 'require');
    }

    public function sceneGetOneToOneChat()
    {
        $this->append('param.receiver', 'require|integer')
            ->append('param.sender', 'require|integer');
    }

    // GetOneToSystemChat 验证场景定义
    public function sceneGetOneToSystemChat()
    {
        $this->append('param.receiver', 'require|integer')
            ->append('param.system_user_mark', 'require');
    }

    // HasMessage 验证场景定义
    public function sceneHasMessage()
    {
        return $this->append('param.filter', 'require');
    }

    public function getProducerAssistantMessageUnReadCount()
    {
        return $this->append([
            'param.notify_type_list', 'array',
        ]);
    }
}
